package com.ag.hmk.service.impl;

import java.util.List;

import com.ag.bean.TbGoods;
import com.ag.common.IDUtil;
import com.ag.hmk.dao.HmkGoodsDAO;
import com.ag.hmk.service.GoodsService;
/**
 * 
 * @author 黄木看
 * 物品服务接口的实现
 *
 */
public class GoodsServImpl implements GoodsService {

	

	private HmkGoodsDAO hmkGoodsDAO;
	
	
	/*
	 * 删除一条记录(by id)
	 */
	public void delete(String goodsID) {
		if (goodsID!=null) {
			TbGoods goods = hmkGoodsDAO.findById(goodsID);
			if (goods!=null) {
				goods.setA(IDUtil.DELETE);
				hmkGoodsDAO.attachDirty(goods);
				
			}
		}
	}

	/*
	 * 查询所有记录
	 */
	public List<TbGoods> findAll() {
		return hmkGoodsDAO.findByA(IDUtil.PRESERVE);
	}

	/*
	 * 查询一条记录（by id）
	 */
	public TbGoods findByID(String goodsID) {
		if (goodsID!=null) {
			return hmkGoodsDAO.findById(goodsID);
		} else {
			return null;
		}
	}

	/*
	 * 新增或更新记录
	 */
	public void save(TbGoods goods) {
		if (goods!=null) {
			goods.setA(IDUtil.PRESERVE);
			hmkGoodsDAO.attachDirty(goods);
		}
	}

	/*
	 *查询物品是否存在 
	 */
	@Override
	public boolean findExit(String hql) {
		boolean exit=false;
		List list = null;
		try {
			list = hmkGoodsDAO.hqlQuery(hql);
			if (list!=null) {
				int count =((Long) list.iterator().next()).intValue();
				if (count!=0) {
					exit = true;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return exit;
	}
	public void setHmkGoodsDAO(HmkGoodsDAO hmkGoodsDAO) {
		this.hmkGoodsDAO = hmkGoodsDAO;
	}

}
